package demo1;

import java.util.Arrays;
import java.util.Comparator;

public class Test {

    public static void bubbleSort(Comparable[] comparables){
        for (int i = 0; i < comparables.length-1; i++) {
            for (int j = 0; j < comparables.length-1-i; j++) {
                if(comparables[j].compareTo(comparables[j+1]) > 0){
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j+1];
                    comparables[j+1] = tmp;
                }
            }
        }
    }
    public static void bubbleSort(Staff[] staff, Comparator<Staff> comparator){
        for (int i = 0; i < staff.length-1; i++) {
            for (int j = 0; j < staff.length-1-i; j++) {
                if(comparator.compare(staff[j], staff[j+1]) > 0){
                    Staff tmp = staff[j];
                    staff[j] = staff[j+1];
                    staff[j+1] = tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Staff[] staff = new Staff[3];
        staff[0] = new Staff("kay", 26, 13500);
        staff[1] = new Staff("alivia", 25, 15000);
        staff[2] = new Staff("ben", 20, 4000);

        NameComparator nameComparator = new NameComparator();
        AgeComparator ageComparator = new AgeComparator();
        SalaryComparator salaryComparator = new SalaryComparator();

        // bubbleSort(staff, salaryComparator);
        bubbleSort(staff);
        System.out.println(Arrays.toString(staff));
    }
    public static void main1(String[] args) {
        Staff[] staff = new Staff[3];
        staff[0] = new Staff("kay", 26, 13500);
        staff[1] = new Staff("alivia", 25, 15000);
        staff[2] = new Staff("ben", 20, 4000);

        Arrays.sort(staff);
        System.out.println(Arrays.toString(staff));
    }
}
